************************** printbd **************************************
** NO ES ESTATICA PQ ES LLAMADA DESDE MENUP.PRG
************************************************************************
// function printbd()
LOCAL cbd := SPACE(8)
LOCAL cft := SPACE(8)
LOCAL cond := SPACE(50)
LOCAL nreg := 0
LOCAL bcond
LOCAL aestru := {}
LOCAL pos := 0
LOCAL apan := {}, acampos := {}
LOCAL lin,col,i, cimpri := "S", nkey
cls


@10,05 say "BASE DE DATOS " get cbd picture "!!!!!!!!"
@12,05 say "FICHERO DE TEXTO " get cft picture "!!!!!!!!"
@13,05 say "En la condicion comillas simples y fecha : mm/dd/aa"
@14,05 say "CONDICION " get cond picture "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"

@16,05 say "DESDE " get nreg picture "9999999"
READ

if empty(cbd)
	return NIL
endif
cft := iif (EMPTY(cft),"listado.txt",alltrim(cft)+".txt")

if nreg <= 0
	nreg := 1
endif

if file(cbd+".dbf")
	cls
	use (cbd) alias ana new
	sele ana
	go top

	lin := 0
	col := 0
	aestru := ana->(dbstruct())
	for i := 1 to len(aestru)
		aadd (apan, aestru[i,1])
	next

	do while LastKey() != 27

		for i := 1 to len(apan)
			@10+i-1,10 clear to 20+i-1,20
		next
		@15,30 say "<ESC> Fin Seleccion"
		if EMPTY(apan)
			exit
		endif
		pos := achoice (10,10,20,20, apan)
		if pos != 0
			aadd (acampos, {aestru[pos,1], aestru[pos,3]})
			for i := 1 to len(acampos)
				@0,0 say "CAMPOS ELEGIDOS :"
				@1+int((10*(i-1))/80),(10*(i-1))%80 say acampos[i,1]
			next
			adel (apan, pos)
			asize(apan,(len(apan)-1))
			adel (aestru, pos)
			asize(aestru,(len(aestru)-1))

		endif
	enddo
	nkey := LastKey()
	cls
	@10,10 say "Imprimir " get cImpri picture "!" valid cImpri $ "SsNn"
	READ

	if LastKey() == 27
		close ana
		return NIL
	endif
	if cImpri != "S"
		close ana
		return NIL
	endif

	if EMPTY(cond)
		cond := ".t."
	endif
	cond := "{| | "+ alltrim(cond) + " .and. ana->(!EOF()) }"

	bcond := &cond

	set printer to (cft)
	set device to printer
	@0,0 say chr(15)
	@lin, 00 say "Listado de "+cbd+" "+dtoc(date())
	lin++
	for i := 1 to len(acampos)
		@lin,col say acampos[i,1]
		col+= (acampos[i,2]+2)
	next
	lin += 2
	sele ana
	go nreg
	do while ana->(!EOF())
		if EVAL(bcond)
			col := 0
			for i := 1 to len(acampos)
				@lin,col say ana->&(acampos[i,1])
				col+= (acampos[i,2]+2)
			next
			lin++
		endif
		skip alias ana
	enddo
	**ana200
	@lin,0 say chr(18)
	eject

	set printer to
	set device to screen


endif
close ana
return .t.

